package com.spring.core.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * @Description: This is a sample class.
 * @Author: Simon
 */
public class FileSystemResource implements Resource{

    private final String filePath;

    public FileSystemResource(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public InputStream getInputStream() throws IOException {

        try {
            File file = new File(filePath);
            Path path = file.toPath();
            return Files.newInputStream(path);
        }catch (Exception e){
            throw new FileNotFoundException("file not found");
        }
    }
}
